<template>
  <!-- 一线城市学历折线图 -->
  <div class="barChart"></div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      data: [],
      cityData: [],
      sal1: [],
      sal2: [],
      sal3: [],
      xueliData: []
    };
  },
  props: {
    oneCityData: Array
  },
  watch: {
    oneCityData(newV,oldV) {
      if (newV.length>0) this.getData(newV)
    }
  },
  methods: {
    getData(newV) {
        newV.forEach(item => {
            if (item.length > 0) {
                this.cityData.push(item[0].location)
                this.sal1.push(item[0].salary)
                this.sal2.push(item[1].salary)
                this.sal3.push(item[2].salary)
            }
        })
        this.setChart()
    },
    setChart() {
      let option = {
        title: {
          text: "一线城市学历与薪资",
          top: "5%",
          left: "3%",
          textStyle: {
            color: "#75deef",
            fontSize: 13,
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // Use axis to trigger tooltip
            type: "shadow", // 'shadow' as default; can also be 'line' or 'shadow'
          },
        },
        legend: {
         data: ['大专', '本科', '硕士'],
          textStyle: {
            color: "#fff",
          },
          top: "5%",
          right: "2%",
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          data: this.cityData,
          axisLine: {
            lineStyle: {
              color: "#fff",
            },
          },
          nameTextStyle: {
            color: "#fff",
          },
        },
        yAxis: {
          type: "value",
          axisLine: {
            lineStyle: {
              color: "#fff",
            },
          },
        },
        series: [
          {
            name: '大专',
            type: "line",
            label: {
              show: true,
            },
            itemStyle: {
              color: 'rgb(10,255,255)'
            },
            emphasis: {
              focus: "series",
            },
            data: this.sal1,
          },
          {
            name: '本科',
            type: "line",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            itemStyle: {
              color: 'rgb(252,132,88)'
            },
            data: this.sal2,
          },
          {
            name: '硕士',
            type: "line",
            label: {
              show: true,
            },
            emphasis: {
              focus: "series",
            },
            itemStyle: {
              color: 'rgb(250,200,88)'
            },
            data: this.sal3,
          },
        ],
      };
      let myChart = this.$echarts(this.$el);

      myChart.clear();
      myChart.resize();
      myChart.setOption(option);
    },
  },
  mounted() {
    // this.getData();
  },
};
</script>

<style lang="less" scoped>
.barChart {
  width: 100%;
  height: 100%;
}
</style>